using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Admin;
using System;
using System.Data;
using System.Text;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class HL_Admin_Admin_HotKey : Admin, IRequiresSessionState
{
	protected Literal JavascriptLiteral;
	protected GridView GridView1;
	protected Button DelButton;
	protected DropDownList ConditonsDrop;
	protected TextBox DeleteNums;
	protected Button DelConditions;
	protected TextBox hot_key_name;
	protected TextBox hot_key_hits;
	protected HiddenField hotkey_id;
	protected DropDownList hot_key_type;
	protected TextBox hot_key_url;
	protected Button AddNewHotKey;
	protected Button btn_updateHotKey;
	protected ObjectDataSource ObjectDataSource1;
	private Shop_HotKey _shk = null;
	protected string wherestr = "";
	protected string linkhead = "";
	protected bool tag = true;
	public string m_arrID = "";
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected Shop_HotKey m_shk
	{
		get
		{
			Shop_HotKey shk;
			if (this._shk == null)
			{
				this._shk = new Shop_HotKey(this.conn);
				shk = this._shk;
			}
			else
			{
				shk = this._shk;
			}
			return shk;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			this.BindList();
		}
	}
	protected void BindList()
	{
		this.QueryString();
		this.GridView1.DataSource = this.m_shk.GetAllHotKeys();
		this.GridView1.DataBind();
	}
	protected void QueryString()
	{
		if (this.wherestr != "")
		{
			this.wherestr = "and" + this.wherestr;
			this.wherestr = this.wherestr.Replace("andand", "Where");
		}
	}
	protected void GridView1_DataBound(object sender, EventArgs e)
	{
		if (this.GridView1.Rows.Count > 0)
		{
			StringBuilder stringBuilder = new StringBuilder();
			foreach (GridViewRow gridViewRow in this.GridView1.Rows)
			{
				HyperLink hyperLink = (HyperLink)gridViewRow.Cells[2].Controls[0];
				string text = "";
				string text2 = "";
				if (hyperLink != null)
				{
					text = hyperLink.NavigateUrl;
					text2 = hyperLink.Text;
				}
				stringBuilder.Append(string.Concat(new string[]
				{
					"HotKeyArray[",
					gridViewRow.Cells[1].Text,
					"]=[\"",
					text2,
					"\",\"",
					gridViewRow.Cells[3].Text,
					"\",\"",
					text,
					"\"];"
				}));
			}
			this.JavascriptLiteral.Text = stringBuilder.ToString();
		}
	}
	protected void AddNewHotKey_Click(object sender, EventArgs e)
	{
		string text = this.hot_key_name.Text;
		int hits = Convert.ToInt32(this.hot_key_hits.Text);
		string url = this.hot_key_url.Text;
		url = "/Shop/Search/" + this.hot_key_type.SelectedValue + ".aspx?title=" + base.Server.UrlEncode(text);
		if (this.m_shk.AddHotKey(text, url, hits))
		{
			this.WriteSuccessMsg("", Language.GetAdminMsg("Common/AddSuccess"), "Admin_HotKey.aspx");
		}
	}
	protected void DelConditions_Click(object sender, EventArgs e)
	{
		bool flag = false;
		if (flag)
		{
			this.WriteSuccessMsg("", Language.GetAdminMsg("Common/DeleteSuccess"), "admin_hotkey.aspx");
		}
		else
		{
			this.WriteErrMsg("", Language.Get("Common/Fail", "0"), "");
		}
	}
	protected void DelButton_Click(object sender, EventArgs e)
	{
		bool flag = false;
		if (flag)
		{
			this.WriteSuccessMsg("", Language.GetAdminMsg("Common/DeleteSuccess"), "admin_hotkey.aspx");
		}
		else
		{
			this.WriteErrMsg("", Language.Get("Common/Fail", "0"), "");
		}
	}
	protected void btn_update_Command(object sender, CommandEventArgs e)
	{
		this.btn_updateHotKey.Visible = true;
		this.AddNewHotKey.Visible = false;
		int hotKey = int.Parse(e.CommandArgument.ToString());
		this.hotkey_id.Value = hotKey.ToString();
		DataTable hotKeyByID = this.m_shk.getHotKeyByID(hotKey);
		if (hotKeyByID.Rows.Count > 0)
		{
			this.hot_key_name.Text = hotKeyByID.Rows[0]["KeyName"].ToString();
			this.hot_key_hits.Text = hotKeyByID.Rows[0]["hits"].ToString();
			this.hot_key_url.Text = hotKeyByID.Rows[0]["search_url"].ToString();
		}
	}
	protected void btn_updateHotKey_Click(object sender, EventArgs e)
	{
		string text = this.hot_key_name.Text;
		int hits = Convert.ToInt32(this.hot_key_hits.Text);
		string text2 = this.hot_key_url.Text;
		int num = text2.LastIndexOf("=");
		int iD = int.Parse(this.hotkey_id.Value);
		text2 = text2.Substring(0, num + 1) + base.Server.UrlEncode(text);
		if (this.m_shk.UpdateHotKey(iD, text, hits, text2))
		{
			this.WriteSuccessMsg("", Language.GetAdminMsg("Common/EditSuccess"), "Admin_HotKey.aspx");
		}
	}
	protected void Link_Command(object sender, CommandEventArgs e)
	{
		if (!this.m_shk.DeleteHotKey(int.Parse(e.CommandArgument.ToString())))
		{
			this.WriteSuccessMsg("", Language.Get("Admin/Common/DeleteFail"), "");
		}
		else
		{
			this.BindList();
		}
	}
	protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
	{
	}
}
